package toUse {
	import rule.IObserver;
	import rule.ISubject;
	
	/**
	 * ...
	 * @author wibrst@qq.com
	 */
	public class WeatherData implements ISubject{
		
		public function WeatherData() {
			this._vcObservers = new Vector.<IObserver>;
		}
		
		/// provide to simulate		
		public function simulateChange( nTemp:Number, nHumi:Number, nPres:Number ):void {
			this._nTemp = nTemp;
			this._nHumi = nHumi;
			this._nPress = nPres;
			this.measurementsChanged();
		}
		
		/// provide for device		
		public function measurementsChanged():void {
			this.notifyObservers();
		}
		
		/* INTERFACE rule.ISubject */
		
		public function regObserver(obs:IObserver):void {
			this._vcObservers.push( obs );
		}
		
		public function unregObserver(obs:IObserver):void {
			var idx:Number = this._vcObservers.indexOf( obs, 0 );
			if ( idx != -1) {
				this._vcObservers.splice( idx, 1 );
			}
		}
		
		public function notifyObservers():void {
			for each ( var obs:IObserver in this._vcObservers ) {
				obs.update( this._nTemp, this._nHumi, this._nPress ); 
			}
		}
		
		/// variable members
		
		private var _vcObservers:Vector.<IObserver>;
		private var _nTemp:Number;
		private var _nHumi:Number;
		private var _nPress:Number;
	}

}